<?php

namespace app\admin\service\statistics\promotion\h5;

use app\admin\service\statistics\promotion\AbstractComputeStatistician;
use app\admin\service\statistics\traits\CompletionTrait;
use function show_percentage;

/**
 * 渠道数据 H5 登录注册率
 * Class LoginRegisterRate
 * @package app\admin\service\statistics\promotion
 */
class LoginRegisterRate extends AbstractComputeStatistician
{
    // 补齐
    use CompletionTrait;

    // new_member_count,captcha_count
    protected function compute(int $index)
    {
        $statisticians = $this->statisticians;

        $new_member_count = $statisticians['h5-new_member_count'][$index]['value'] ?? null;

        $captcha_count = $statisticians['h5-captcha_count'][$index]['value'] ?? null;

        if (!is_numeric($new_member_count) || !is_numeric($captcha_count)) {
            return '';
        }

        return show_percentage($new_member_count, $captcha_count, 1);
    }

    protected function getDefaultValue()
    {
        return '0%';
    }
}